package com.block.account.service.impl;

import com.block.account.model.dto.EntryAccountDTO;
import com.block.db.entity.AccountItemChannleHis;
import com.block.db.mapper.AccountItemChannleHisMapper;
import com.block.account.service.IAccountItemChannleHisService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * <p>
 * 渠道账户流水表 服务实现类
 * </p>
 *
 * @author 
 * @since 2023-02-02
 */
@Service
public class AccountItemChannleHisServiceImpl extends ServiceImpl<AccountItemChannleHisMapper, AccountItemChannleHis> implements IAccountItemChannleHisService {

    /**
     * 新增账户变化历史
     * @param entryAccountDTO
     * @return
     */
    @Override
    public boolean saveChannelHisInfo(EntryAccountDTO entryAccountDTO){

        AccountItemChannleHis channelHis = new AccountItemChannleHis();
        channelHis.setDateInfo(LocalDate.now().toString());
        channelHis.setAccountId(Integer.valueOf(entryAccountDTO.getItemAccountId()));
        channelHis.setChannelCode(entryAccountDTO.getItemAccountKey());
        channelHis.setChannelName(entryAccountDTO.getItemAccountName());

        channelHis.setActionType(entryAccountDTO.getActionType());

        channelHis.setChangeAmount(entryAccountDTO.getChangeAmount());
        channelHis.setOriginAmount(entryAccountDTO.getOriginAmount());
        channelHis.setCurrentAmount(entryAccountDTO.getCurrentAmount());

        channelHis.setMainAccountId(entryAccountDTO.getMainAccountId());
        channelHis.setMainAccountName(entryAccountDTO.getMainAccountName());

        channelHis.setDataId(entryAccountDTO.getRecordId());
        channelHis.setOperatorId(entryAccountDTO.getOperatorId());
        channelHis.setOperatorName(entryAccountDTO.getOperatorName());

        boolean saveRes = this.save(channelHis);

        return saveRes;
    }

}
